package com.situ.feemanagement.controller;

import com.situ.feemanagement.pojo.entity.Department;
import com.situ.feemanagement.pojo.query.DepartmentQuery;
import com.situ.feemanagement.service.IDepartmentService;
import com.situ.feemanagement.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/department")
public class DepartmentController {

    @Autowired
    private IDepartmentService departmentService;

    @GetMapping("/selectAll")
    public Result selectAll() {
        List<Department> list = departmentService.selectAll();
        return Result.ok(list);
    }

    @GetMapping("/list")
    public Result list(DepartmentQuery departmentQuery) {
        Map<String, Object> map = departmentService.selectByPage(departmentQuery);
        return Result.ok(map);
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable Integer id) {
        departmentService.deleteById(id);
        return Result.ok("删除成功");
    }

    @DeleteMapping("/deleteAll/{ids}")
    public Result deleteAll(@PathVariable Integer[] ids) {
        departmentService.deleteByAll(ids);
        return Result.ok("删除成功");
    }

    @PostMapping("/add")
    public Result add(@RequestBody Department department) {
        departmentService.add(department);
        return Result.ok("添加成功");
    }

    @GetMapping("/selectById/{id}")
    public Result selectById(@PathVariable Integer id) {
        Department department = departmentService.selectById(id);
        return Result.ok(department);
    }

    @PutMapping("/update")
    public Result update(@RequestBody Department department) {
        departmentService.update(department);
        return Result.ok("更新成功");
    }
}
